<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title> 代理管理系统</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="apple-mobile-web-app-status-bar-style" content="black"> 
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="format-detection" content="telephone=no">
  
  <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
  <style type="text/css">
    
  </style>
</head>
<body>
<div class="layui-layout layui-layout-admin">
  <div class="layui-header">
    <div class="layui-logo">  </div>
    <!-- 头部区域（可配合layui已有的水平导航） -->
    <ul class="layui-nav layui-layout-left">
      <!-- <li class="layui-nav-item"><a href="">小程序管理</a></li> -->
    </ul>
    <ul class="layui-nav layui-layout-right">
      <li class="layui-nav-item">
        <a href="javascript:;">
          {$Think.session.username}
        </a>
        <dl class="layui-nav-child">
          <dd><a href="{:U('Public/logout')}">退出登录</a></dd>
          <!-- <dd><a href="">安全设置</a></dd> -->
        </dl>
      </li>
    </ul>
  </div>
  
  <div class="layui-side layui-bg-black">
    <div class="layui-side-scroll">
      <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
      <ul class="layui-nav layui-nav-tree"  lay-filter="test">
        <li class="layui-nav-item"><a href="{:U('Index/index')}">首页</a></li>
        <li class="layui-nav-item"><a href="{:U('User/index')}">代理管理</a></li>
        <li class="layui-nav-item"><a href="{:U('Wechat/index')}">小程序管理</a></li>
        <li class="layui-nav-item layui-this"><a href="{:U('Wechat/audit')}">审核生成小程序请求</a></li>
        <li class="layui-nav-item"><a href="{:U('Index/edit')}">修改账号</a></li>
        <li class="layui-nav-item"><a href="{:U('Public/logout')}">退出登录</a></li>
      </ul>
    </div>
  </div>
  
  <div class="layui-body">
    <!-- 内容主体区域 -->
    <div style="padding: 15px;">
      <fieldset class="layui-elem-field layui-field-title">
        <legend>我的小程序</legend>
      </fieldset>
      <div id="view"></div>
    </div>
  </div>
  
  <div class="layui-footer">
    <!-- 底部固定区域 -->
    © 2017-2018 <a href="https://www.58zltc.com" target="_blank">  </a> All Rights Reserved.
  </div>
</div>
<script id="tpl" type="text/html">
  <table class="layui-table">
    <thead>
      <tr>
        <th>店铺名称</th>
        <th>所属分类</th>
        <th>申请模板</th>
        <th>状态</th>
        <th>操作</th>
      </tr> 
    </thead>
    <tbody>
      {{#  layui.each(d, function(index, item){ }}
      <tr>
        <td>{{ item.name }}</td>
        <td>{{ item.cate }}</td>
        <td>
          {{#  if(item.type == 'car'){ }}
          汽车
          {{#  } }}
          {{#  if(item.type == 'jiaoyu'){ }}
          教育
          {{#  } }}
          {{#  if(item.type == 'jiancai'){ }}
          建材
          {{#  } }}
          {{#  if(item.type == '' ||item.type == ' '){ }}
          通用
          {{#  } }}
        </td>
        <td>
          {{# if(item.has_mini == 1){ }}<span class="layui-badge layui-bg-blue">审核中</span>{{#  }}}
          {{# if(item.has_mini == 2){ }}<span class="layui-badge">已通过</span>{{#  } }}
          {{# if(item.has_mini == 3){ }}<span class="layui-badge layui-bg-green">已生成</span>{{#  } }}
        </td>
        <td>
          {{# if(item.has_mini == 1){ }}
            <button data-id="{{ item.shop_id }}" class="edit layui-btn layui-btn-small">通过审核</button>
          {{#  }}}
        </td>
      </tr>
      {{#  }); }}
      {{#  if(d.length === 0){ }}
        无数据
      {{#  } }}
    </tbody>
  </table>
  <div id="page-box"></div>
</script>
<script src="__PUBLIC__/layui/layui.js" charset="utf-8"></script>
<script>
//JavaScript代码区域
layui.use(['element','laypage','laytpl','layer'], function(){
  var element = layui.element
  ,$ = layui.jquery
  ,layer = layui.layer
  ,laypage = layui.laypage
  ,laytpl = layui.laytpl;

  $("#view").on('click', '.edit', function(event) {
    var id = $(this).data('id');
    $.post("{:U('auditc')}", {id: id}, function(e) {
      if(e.status == 1){
        layer.msg(e.info,{icon: 6,time:1000});
        setTimeout("location.reload()",1000);
      }else{
        layer.msg(e.info,{icon:1,time:1000});
      }
    });
  });

  getList(1, 10);

  function getList(page, limit){
    $.get("{:U('audit')}?page="+page+"&limit="+limit,function(data){
      var view = document.getElementById('view');
      var getTpl = tpl.innerHTML;
      laytpl(getTpl).render(data.list, function(html){
        view.innerHTML = html;
      });
      laypage.render({
        elem: 'page-box'
        ,count: data.count
        ,curr: page
        ,layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
        ,jump: function(obj, first){
          console.log(obj)
          if(!first){
            getList(obj.curr, obj.limit);
          }
        }
      });
    })
  }  
  
});
</script>
</body>
</html>
